package com.santu.edu.supporter.biz.buildings.serice.impl;

import com.santu.edu.supporter.biz.buildings.dao.BuildingsDao;
import com.santu.edu.supporter.biz.buildings.pojo.dto.BuildingsDTO;
import com.santu.edu.supporter.biz.buildings.pojo.enums.BuildingsType;
import com.santu.edu.supporter.biz.buildings.serice.BuildingsService;
import com.santu.edu.supporter.biz.school.pojo.dto.SchoolDTO;
import com.santu.edu.supporter.biz.school.service.SchoolService;
import com.santu.edu.supporter.exception.BizException;
import com.santu.edu.supporter.exception.CustomError;
import com.santu.edu.supporter.util.UuidUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author luoyaoqi
 * @createTime 2024/2/20
 * @description
 */
@Service
@RequiredArgsConstructor
public class BuildingsServiceImpl implements BuildingsService {

    private final BuildingsDao buildingsDao;

    private final SchoolService schoolService;

    @Override
    public Boolean addBuilding(String buildName, Integer typeCode,String schoolId) {
        BuildingsType buildingsType = BuildingsType.convert(typeCode);
        String buildingsId = UuidUtils.getUuid(8);
        buildingsDao.addBuilding(BuildingsDTO.createItem(buildingsId,buildName,buildingsType,schoolId));
        return true;
    }

    @Override
    public Boolean removeBuilding(String buildingsId) {
        buildingsDao.removeBuilding(buildingsId);
        return true;
    }

    @Override
    public List<BuildingsDTO> getBuildingsList(Integer typeCode,String schoolId) {
        SchoolDTO school = schoolService.getSchoolById(schoolId);
        if (school == null) {
            throw BizException.causeBy(CustomError.REQUEST_ERROR,"学校不存在");
        }
        BuildingsType buildingsType = BuildingsType.convert(typeCode);
        return buildingsDao.getBuildingsList(buildingsType,schoolId);
    }

    @Override
    public List<BuildingsDTO> getBuildsByIdList(List<String> buildIdList) {
        return buildingsDao.getBuildsByIdList(buildIdList);
    }
}
